<template>
  <el-dialog :title="title" :visible.sync="dialogVisible" @close="close" :close-on-click-modal="false" width="850px">
    <div class="form-box">
      <div v-if="!guoqi&&!huishouObj.acceptTenantId" style="margin-bottom: 10px;border-radius: 2px; background-color: rgb(237 91 91);">
            <el-statistic format="HH小时mm分钟ss秒" v-if="baojiaEndTime" @finish="hilarity" :value="baojiaEndTime" time-indices title="">
              <template slot="prefix">
                <span style="font-size: 14px;color: #fff;line-height: 30px;">该商品距离过期还有</span>
              </template>
            </el-statistic>
          </div>
      <el-table border :data="list" style="width: 100%;">
        <el-table-column align="center" prop="createName" label="报价人">
          <template slot-scope="scope">
            <span>{{ `报价人${scope.$index+1}` }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="price" label="报价">
        </el-table-column>

        <el-table-column align="center" prop="createTime" label="报价时间">
        </el-table-column>
        <el-table-column align="center" label="状态" width="120">
          <template slot-scope="scope">
            <el-tag type="" v-if="scope.row.status==1">已接受</el-tag>
            <el-tag type="danger" v-if="scope.row.status==2">已拒绝</el-tag>
            <el-tag type="success" v-if="scope.row.status==3">已完成</el-tag>
            <el-button type="text" v-if="scope.row.status==0&&!guoqi" @click="jieshou(scope.row)">接受报价</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-divider content-position="left">账号信息</el-divider>
      <el-descriptions title="" :column="1" border :labelStyle="{width:'100px'}">
        <el-descriptions-item label="游戏">{{huishouObj.gameName}}</el-descriptions-item>
        <el-descriptions-item label="游戏账号">{{huishouObj.accountNumber}}</el-descriptions-item>
        <el-descriptions-item label="区服">{{huishouObj.region}}</el-descriptions-item>
        <el-descriptions-item label="图片" :span="3" :labelStyle="{width:'120px'}">
          <div class="flex img-box">
            <el-image :src="item" @click="imgView(imgList,ind)" v-for="(item, ind) in imgList" :key="item" class="lin-item"></el-image>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="简介">
          <div style="max-height: 300px;overflow-y: auto;">
            {{huishouObj.des}}
          </div>
        </el-descriptions-item>

      </el-descriptions>

    </div>
  </el-dialog>
</template>

<script>
import jingpaiApi from "@/api/jingpaishichang/index.js";
export default {
  name: "",
  data() {
    return {
      dialogVisible: false,
      loading: false,
      title: "报价列表",
      list: [],
      total: 0,

      // 表单参数
      form: {},
      rules: {},
      huishouObj: {},

      backId: "",
      imgList: [],
      baojiaEndTime: "",
      timer: null,
      guoqi: false,
    };
  },
  created() {},
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },

  methods: {
    // 打开弹窗
    open(id) {
      this.dialogVisible = true;
      this.guoqi = false;
      this.backId = id;
      this.getDetail();
    },
    getDetail() {
      jingpaiApi.getbackCluemyListInfo(this.backId).then((res) => {
        this.list = res.data.backClueQuotations;
        this.huishouObj = res.data;
        if (this.huishouObj.img) {
          let arr = [];
          let list = JSON.parse(this.huishouObj.img);
          if (list.length) {
            list.forEach((element) => {
              arr.push(element.url);
            });
            this.imgList = arr;
          }
        } else {
          this.imgList = [];
        }
        this.getEndTime();
        // this.intervalFn();
      });
    },
    // 计算倒计时的计时器
    // intervalFn() {
    //   this.timer = setInterval(() => {
    //     this.getEndTime();
    //   }, 1000);
    // },
    hilarity(){
      this.isEdit = false;
    },
    // 计算报价结束倒计时
    getEndTime() {
      const now = new Date();
      const end = new Date(this.huishouObj.expiredTime||"2024-11-20 15:24:00");
      if (now >= end) {
        // 报价已结束
        this.isEdit = false;
      } else {
        // const shengyu = new Date(end.getTime() - now.getTime());
        this.baojiaEndTime =end;
        // console.log("%c Line:130 🍷 this.baojiaEndTime", "color:#e41a6a", this.baojiaEndTime);
      }
    },
    jieshou(row) {
      this.$confirm(
        "接受报价后将不能接受其他回收商的报价，是否继续？",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          let obj = {
            acceptTenantId: row.createTenantId,
            id: this.backId,
          };
          jingpaiApi.getbackCluemyListJieshou(obj).then((res) => {
            this.$alert("已接受报价，请等待买家发起交易！");
            this.getDetail();
          });
        })
        .catch(() => {});
    },
    close() {
      if (this.timer) {
        clearInterval(this.timer);
      }
      this.baojiaEndTime = ''
      this.$emit('close')
      this.dialogVisible = false;
      this.$parent.getList();
    },
    // 图片数组预览
    imgView(list, and) {
      this.$viewerApi({
        images: list,
        options: {
          initialViewIndex: and,
        },
      });
    },
  },
};
</script>
<style scoped lang="css">
.center {
  text-align: center;
}

.img-box {
  width: 700px;
}
.img-box {
  flex-wrap: wrap;
}
.lin-item {
  width: 100px;
  height: 100px;
  cursor: pointer;
  margin-right: 10px;
  margin-bottom: 10px;
}

::v-deep .el-statistic .number {
  font-size: 16px;
  color: #f4f81e;
}
</style>
